﻿using Catastrophe.BasePC.UI.File;
using Catastrophe.Common.FileM;
using Catastrophe.CommonCore.FileM;
using Catastrophe.Initialize;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Catastrophe.BasePC.UI.UIMode
{
    /// <summary>
    /// 系统样式
    /// </summary>
    public partial class UcSystemStyleModel : ObservableObject, IFrameFileConfig
    {
        /// <summary>
        /// 
        /// </summary>
        FileConfigManager<FileConfigEntity> ConfigManager { get; set; }

        public ICommand SaveConfig { get; set; }
        public ICommand RefreshConfig { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string heandText { get; set; }


        /// <summary>
        /// 加载的程序集
        /// </summary>
        [ObservableProperty]
        private string moduleIniNameSpace;
        /// <summary>
        /// 主窗口大小
        /// </summary>
        [ObservableProperty]
        private string systemCacheFrm;
        /// <summary>
        /// 登录窗口尺寸
        /// </summary>
        [ObservableProperty]
        private string loginFrmSize;

        /// <summary>
        /// 登录标题
        /// </summary>
        [ObservableProperty]
        private string loginTittle;
        public UcSystemStyleModel()
        {
            ConfigManager = new FileConfigManager<FileConfigEntity>(FileTypeEnum.Json);
            SaveConfig = new RelayCommand(SaveConfigMethod);
            RefreshConfig = new RelayCommand(RefreshConfigMethod);
       

        }

        public void SaveConfigMethod()
        {
            SetValue();
            ConfigManager.Write();
        }

        public void RefreshConfigMethod()
        {
            ConfigManager.ReadEntity();
            GetValue();
        }

        private void GetValue()
        {
            var type1 = typeof(UcSystemStyleModel);
            var type2 = typeof(FileConfigEntity);
            var pros2 = type2.GetProperties();
            foreach (var pro2 in pros2)
            {
                var prop1 = type1.GetProperty(pro2.Name);
                if (prop1 != null)
                {
                    var value = pro2.GetValue(ConfigManager.Value);
                    prop1.SetValue(this, value);
                }
            }
            //ModuleIniNameSpace = ConfigManager.Value.ModuleIniNameSpace;
        }

        private void SetValue()
        {
            var type1 = typeof(UcSystemStyleModel);
            var type2 = typeof(FileConfigEntity);
            var pros1 = type1.GetProperties();
            foreach (var pro1 in pros1)
            {
                var prop1 = type2.GetProperty(pro1.Name);
                if (prop1 != null)
                {
                    var value = pro1.GetValue(this);
                    prop1.SetValue(ConfigManager.Value, value);
                }
            }
        }
    }
}
